Ext.ns('AIR2.Upload');
/***************
 * Upload page
 *
 * Display info about an uploaded csv file, and allow altering the upload and
 * starting the import process.
 */
AIR2.Upload = function() {
    // store to hold the single tank record
    var store = new Ext.data.JsonStore({
        autoLoad: false,
        autoSave: false,
        autoDestroy: true,
        restful: true,
        remoteSort: true,
        writer: new Ext.data.JsonWriter({
            encode: true,
            writeAllFields: false
        }),
        url: AIR2.HOMEURL + '/upload.json',
        listeners: {
            load: function() {store.autoRefresh();},
            save: function() {store.autoRefresh();}
        },
        refreshTask: new Ext.util.DelayedTask(function() {
            store.modified.push(store.getAt(0));
            store.save();
        }),
        autoRefresh: function() {
            if (store.getAt(0).data.tank_status == 'B') {
                store.refreshTask.delay(2000);
            }
        }
    });

    /* create the application */
    var app = new AIR2.UI.App({
        id: 'air2-app',
        items: new AIR2.UI.PanelGrid({
            columnLayout: '21',
            items: [
                AIR2.Upload.Settings(store),
                AIR2.Upload.Meta(store),
                AIR2.Upload.Status(store)
            ]
        })
    });
    app.showLocation(
        AIR2.Upload.UPDATA.radix.tank_file_name,
        'air2-icon-upload',
        AIR2.Upload.UPURL
    );

    // inline-load the store
    store.loadData(AIR2.Upload.UPDATA);
}
